package com.mm.service.impl;

import com.mm.dao.ProtectionMapper;
import com.mm.exception.ServiceException;
import com.mm.model.Protection;
import com.mm.service.ProtectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 保障service实现类
 *
 * @date 2018/7/19 16:33
 */
@Service(value = "protectionService")
public class ProtectionServiceImpl implements ProtectionService {
	@Autowired
	private ProtectionMapper protectionMapper;

	/**
	 * 保存保障
	 *
	 * @param protection Protection
	 */
	@Override
	public void saveProtection(Protection protection) {
		protectionMapper.insertProtection(protection);
	}

	/**
	 * 更新保障
	 *
	 * @param protection Protection
	 */
	@Override
	public void updateProtection(Protection protection) {
		protectionMapper.updateProtectionById(protection);
	}

	/**
	 * 获取保障
	 *
	 * @param protectionId 保障ID
	 * @return Protection
	 * @throws ServiceException
	 */
	@Override
	public Protection getOneProtectionById(Long protectionId) throws ServiceException {
		if (protectionId == null) {
			throw new ServiceException("保障ID不能为空");
		}
		return protectionMapper.getOneProtectionById(protectionId);
	}

	/**
	 * 通过保障ID删除保障
	 *
	 * @param protectionId 保障ID
	 * @throws ServiceException
	 */
	@Override
	public void deleteProtectionById(Long protectionId) throws ServiceException {
		if (protectionId == null) {
			throw new ServiceException("保障ID不能为空");
		}
		protectionMapper.deleteProtectionById(protectionId);
	}
}
